package behavioralPattern.chain_of_responsibility.example03;

import behavioralPattern.chain_of_responsibility.example02.AuthInfo;
import behavioralPattern.chain_of_responsibility.example02.AuthService;

import java.text.ParseException;
import java.util.Date;

/**
 * 具体处理者
 */
public class Auth_2 extends AuthLink{

    private Date begin = format.parse("2022-11-11");
    private Date end = format.parse("2022-11-30");

    public Auth_2(String levelUserId, String levelUserName) throws ParseException {
        super(levelUserId, levelUserName);
    }


    @Override
    public AuthInfo doAuth(String uId, String orderId, Date authDate) {
        Date date = AuthService.queryAuthInfo(levelUserId, orderId);
        if (null == date){
            return new AuthInfo("0002","单号：" + orderId,"状态：二级待审批:" + levelUserName);
        }

        AuthLink next_1 = super.getNext();
        if (null == next_1){
            return new AuthInfo("0002","单号：" + orderId,"状态：二级审批完成！！:" + levelUserName);
        }

        if (authDate.before(begin) || authDate.after(end)){
            return new AuthInfo("0002","单号：" + orderId,"状态：二级审批完成！！:" + levelUserName);
        }
        return next.doAuth(uId,orderId,authDate);
    }
}
